<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="../../css/layui.css">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
    <script src="../../js/common.js"></script>
</head>
<body>
    <style>
        .layui-btn{
            padding: 0 7px !important;
        }
        .layui-laypage a, .layui-laypage span{
            background-color: #f2f2f2;
        }
    </style>
<script type="text/html" id="caozuo">
    <input type="submit"  value="使用" class="layui-btn " lay-submit="" lay-event="updateTheme"/>
</script>

<div class="layui-form-item layui-col-xs12 site-demo-button" id="layerDemo" style="margin-left: 2%;">
</div>

<script type="text/html" id="tol">

    <div>
        <div style="float:left;">主题管理</div>
        <div style="float:right;margin-right: 50px">共有数据：<span id="count"></span>条</div>
    </div>

</script>
<div class="layui-form">

    <table class="layui-table" id="themedata" lay-filter="themedata"></table>

    <div id="demo7" style="text-align: center"></div>
</div>
</body>
<!--</div>-->
<script>
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        var table = layui.table;

        var station_ss=layui.data("station_ss");
        var station_id=station_ss.station_ids.id;

        table.render({
            elem: "#themedata",
            url: "/admin/theme/query/themeAll?station_id="+station_id+"&theme_status=启用&theme_audit_pc_audited=0&theme_audit_android_audited=0&theme_admin=1",
            id: "t",
            toolbar:"#tol",
            cols: [[{
                title: "主题编号",
                field: "theme_id",
                width: "21%",
                align: "center"
            },
                {
                    title: "主题名称",
                    field: "theme_name",
                    width: "21%",
                    align: "center"
                }
                ,   {
                    title: "主题图片",
                    field: "theme_image",
                    width: "22%",
                    align: "center",
                    templet: function(d) {
                        return "<img width='50px' height='50px' src='" + IMAGE_SERVER +"/" + d.theme_image + "'></img>";
                    }
                }
                ,
                {
                    title: "操作",
                    width: "35%",
                    align: "center",
                    toolbar: "#caozuo"
                }
            ]],
            page: true,
            done: function(res, curr, count){
                $("#count").html(count);
            }
        })

        table.on("tool(themedata)", function (obj) {
            var getdata = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

            var s=layui.data("s");
            var tid=s.group.group_id;

            switch (layEvent) {

                case "updateTheme":
                    var shuju={
                        "groupId":tid,
                        "groupDesktopConfiguration":getdata.theme_name
                    }

                    $.ajax({
                        url: "/admin/group/update/groupById",
                        type: 'put',
                        dataType: "json",
                        contentType:"application/json;charset=utf-8",
                        data: JSON.stringify(
                            shuju
                        ),
                        // beforeSend: function () {
                        //     this.layerIndex = layer.load(0, {shade: [0.5, '#393D49']});
                        // },
                        success: function (res) {
                            if (res.code == 500) {
                                layer.msg("修改失败", {icon: 5,time: 1000});//失败的表情
                                return;
                            } else if (res.code == 200) {
                                layer.msg("修改成功", {
                                    icon: 6,//成功的表情
                                    time: 1000, //1秒关闭（如果不配置，默认是3秒）
                                    end:function () {
                                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                        parent.layer.close(index); //再执行关闭
                                        parent.location.reload();
                                    }
                                });
                            }
                        },
                        complete: function () {
                            layer.close(this.layerIndex);
                        },
                    });
                    break;
            }
        });

        form.on('submit(addTheme)',function () {

            location="#/layui/addtheme";
            location.reload();
        })

    function GetRequest() {
        var url = decodeURI(location.search); //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

    var json=GetRequest();

</script>

<!--分页-->
<script>
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;

    });
</script>

